<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"></script>
</head>
</head>
<body>
    <!-- 视图层 -->
    <div id="app">
        {{a}}--{{b}}--{total}
        <!-- v-model进行双向数据绑定 -->
        <input type="text" v-model.Number="a">
        + <input v-model.Number="b" type="text"> 
        = <output>{{total}}</output>
    </div>
    <script>
        new Vue({
            //与视图层进行绑定
            el:"#app",
            //存放vue变量
            data: { 
                a:0,
                b:0,
                total:0,
            },
            //存放 方法函数
            methods: {
                
            },
            //计算属性
            computed: {
                
            },
            //侦听器
            watch: {
                //侦听a的变化
                a(n,o){
                    // console.log(n,o,'n新值','o旧值')

                    this.total = this.a + this.b;

                },
                //侦听b的变化
                b(n,o){
                     this.total = this.a + this.b;
                }
            },
        })
    </script>
</body>
</html>